cmake_minimum_required(VERSION 3.14)
project(ComponentInformationManagementSystem LANGUAGES C CXX)

# --- Standard Settings ---
set(CMAKE_C_STANDARD 99)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_INCLUDE_CURRENT_DIR ON) # Add current source/binary dirs to include path

# --- Find Qt ---
# IMPORTANT: Adjust CMAKE_PREFIX_PATH if your Qt installation is elsewhere!
set(CMAKE_PREFIX_PATH "C:/Qt/6.9.0/mingw_64/lib/cmake" CACHE PATH "Path to Qt installation")
find_package(Qt6 COMPONENTS Widgets Svg SvgWidgets REQUIRED) # Added Svg and SvgWidgets components

# --- Enable Qt Auto Tools ---
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON) # Re-enable to see if it helps with RCC execution

# --- Define Data Path ---
# Absolute path to the source data directory
set(SOURCE_DATA_DIR_PATH ${CMAKE_SOURCE_DIR}/data)
# Escape backslashes for C string literal compatibility on Windows
string(REPLACE "\\" "\\\\" SOURCE_DATA_DIR_PATH_ESCAPED ${SOURCE_DATA_DIR_PATH})
# Add definition accessible globally
add_compile_definitions(SOURCE_DATA_PATH="${SOURCE_DATA_DIR_PATH_ESCAPED}")

# --- Backend Library Definition ---
# --- Backend Library Definition ---
add_library(backend_lib STATIC
    # Add backend source files here:
    backend/component.c
    backend/supplier.c
    # backend/inventory.c # To be implemented later
    # backend/user.c      # To be implemented later
)
# Specify include directories for the backend library
target_include_directories(backend_lib PUBLIC
    ${CMAKE_SOURCE_DIR}/backend # Allows #include "component.h" etc. from backend sources
)
# Add backend include path for the GUI executable as well
include_directories(backend) # Makes backend headers findable by GUI sources

# --- GUI Executable Definition ---
message(STATUS "Configuring GUI executable (ComponentManagerApp)")
add_executable(ComponentManagerApp # Use WIN32 for GUI apps on Windows (Temporarily REMOVED for console output)
    # Add GUI source files here:
    gui/main.cpp
    gui/mainwindow.cpp
    gui/componentdialog.cpp
    gui/supplierdialog.cpp # Add supplier dialog source
    gui/componentdetailpage.cpp # Added component detail page source
    gui/suppliercomponentspage.cpp # Added supplier specific components page source
    # gui/loginwindow.cpp # To be implemented later
    # gui/supplierpanel.cpp # (Panel logic is now in MainWindow)
    # gui/inventorypanel.cpp # To be implemented later
)
# Specify include directories for the GUI executable
target_include_directories(ComponentManagerApp PRIVATE
    ${CMAKE_SOURCE_DIR}/gui # Allows #include "mainwindow.h" etc. from GUI sources
    # Backend includes are handled by the include_directories(backend) above
)
# Link the executable against the backend library and Qt Widgets
target_link_libraries(ComponentManagerApp PRIVATE
    backend_lib # Link against our C backend library
    Qt6::Widgets
    Qt6::SvgWidgets # Link SvgWidgets for QSvgWidget
)
# Add resource files
set(RESOURCE_FILES "${CMAKE_SOURCE_DIR}/gui/resources.qrc")
target_sources(ComponentManagerApp PRIVATE ${RESOURCE_FILES})


# --- Final Messages ---
message(STATUS "Project: ${PROJECT_NAME}")
message(STATUS "Source Directory: ${CMAKE_SOURCE_DIR}")
message(STATUS "Data Directory Path (for C/C++): ${SOURCE_DATA_DIR_PATH_ESCAPED}")
message(STATUS "Qt6 Widgets Found: ${Qt6Widgets_FOUND}")